package leetcode_1001_1100;

import node.TreeNode;

public class LeeCode_1026 {
    public static void main(String[] args) {

    }
    private static int maxAncestorDiff(TreeNode root) {
        int[] ans = new int[1];
        dfs(root, root.val, root.val, ans);
        return ans[0];
    }
    private static void dfs(TreeNode node, int min, int max, int[] ans){
        if (node == null){
            return;
        }
        min = Math.min(node.val, min);
        max = Math.max(node.val, max);
        if (node.left == null && node.right == null){
            ans[0] = Math.max(ans[0], max - min);
            return;
        }
        dfs(node.left, min, max, ans);
        dfs(node.right, min, max, ans);
    }
}
